package rjgc.mall.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import rjgc.mall.common.MessageConstant;
import rjgc.mall.common.MySessionContext;
import rjgc.mall.common.Result;
import rjgc.mall.entity.Collection;
import rjgc.mall.entity.Goods;
import rjgc.mall.entity.User;
import rjgc.mall.entity.vo.CollectionList;
import rjgc.mall.entity.vo.ShoppingCarList;
import rjgc.mall.service.CollectionService;
import rjgc.mall.service.ShoppingCartService;

import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/Collection")
public class CollectionController {

    @Autowired
    private CollectionService collectionService;

    //添加至收藏
    @RequestMapping("/AddToCollection")
    public Integer addToCollection(@RequestParam Integer userid,@RequestBody Goods good) {return collectionService.AddToCollection(userid,good);}
    //从收藏中移除
    @DeleteMapping("/RemoveFromCollection")
    public Integer removefromCollection(@RequestParam Integer id){return collectionService.RemoveFromCollection(id);}
    //根据被选中状态从收藏中移除
    @DeleteMapping("/RemoveFromCollectionByStatus")
    public Integer removefromCollectionByStatus(@RequestParam Integer userid){return collectionService.RemoveFromCollectionByStatus(userid);}
    //查看收藏中的商品
//    @RequestMapping("/ShowUserCollection")
//    public List<Collection> showUserCollection(@RequestParam Integer userid){
//        return collectionService.ShowUserCollection(userid);
//    };
    @RequestMapping("/ShowUserCollection")
    public Result ShowUserCollection(@RequestHeader("userToken") String userToken){
        MySessionContext myContext = MySessionContext.getInstance();
        HttpSession session = myContext.getSession(userToken);
        User user=(User) session.getAttribute("user");
        CollectionList result = collectionService.viewList(user.getId());
        return new Result(true, MessageConstant.USER_GET_COLLECTION,result);
    }
    //全选收藏夹商品
    @RequestMapping("/SelectAll")
    public Integer selectAll(@RequestParam Integer userid){
        return collectionService.SelectAll(userid);
    }
    //全不选收藏商品
    @RequestMapping("/NotSelectAll")
    public Integer notSelectAll(@RequestParam Integer userid){
        return collectionService.NotSelectAll(userid);
    }
    //选择单个商品
    @RequestMapping("/SelectOneOrNot")
    public Integer selectOneOrNot(@RequestParam Integer id){
        return collectionService.SelectOneOrNot(id);
    }

    //将选中商品移入购物车
    @RequestMapping("/MoveToShoppingCart")
    public Integer moveToShoppingCart(@RequestParam Integer userid){return collectionService.MoveToShoppingCart(userid); }
}
